//
//  XYXEmoticonPackage.swift
//  Emoticon
//
//  Created by 亚杏 on 2017/6/5.
//  Copyright © 2017年 oms. All rights reserved.
//

import UIKit
import YYModel

//表情包模型
class XYXEmoticonPackage: NSObject {

    //表情包的分组名
    var groupName: String?
    //表情包目录
    var directory: String? {
        didSet {
            //当设置目录时，从目录下加载 info.plist
            guard let directory = directory,
                let path = Bundle.main.path(forResource: "HMEmoticon.bundle", ofType: nil),
                let bundle = Bundle(path: path),
                let infoPath = bundle.path(forResource: "info.plist", ofType: nil, inDirectory: directory),
               let array = NSArray(contentsOfFile: infoPath) as? [[String: String]],
               let models = NSArray.yy_modelArray(with: XYXEmoticonModel.self, json: array) as? [XYXEmoticonModel]

            else {
                return
            }

            //遍历models,设置每一个表情符号的目录
            for m in models {
                m.directory = directory
            }
            emoticons += models
        }
    }

    //懒加载表情模型数组
    //避免后续解包
    lazy var emoticons = [XYXEmoticonModel]()

    override var description: String {
        return yy_modelDescription()
    }

}
